[ -e /tmp/.failsafe ] && export FAILSAFE=1

if [ -f /etc/banner ]; then
	RELEASE_INFO_ROOT="/rom"

	if [ ! -d "${RELEASE_INFO_ROOT}/etc" ]; then
		RELEASE_INFO_ROOT=""
	fi

	if [ -f "${RELEASE_INFO_ROOT}/etc/openwrt_release" -a -f "${RELEASE_INFO_ROOT}/etc/device_info" -a -x /bin/sed ]; then
		. "${RELEASE_INFO_ROOT}/etc/openwrt_release"
		. "${RELEASE_INFO_ROOT}/etc/device_info"
		sed -e "s/\${DISTRIB_ID}/${DISTRIB_ID//\//\\\/}/" \
		    -e "s/\${DISTRIB_RELEASE}/${DISTRIB_RELEASE//\//\\\/}/" \
		    -e "s/\${DISTRIB_REVISION}/${DISTRIB_REVISION//\//\\\/}/" \
		    -e "s/\${DISTRIB_TARGET}/${DISTRIB_TARGET//\//\\\/}/" \
		    -e "s/\${DISTRIB_ARCH}/${DISTRIB_ARCH//\//\\\/}/" \
		    -e "s/\${DISTRIB_DESCRIPTION}/${DISTRIB_DESCRIPTION//\//\\\/}/" \
		    -e "s/\${DISTRIB_TAINTS}/${DISTRIB_TAINTS//\//\\\/}/" \
		    -e "s/\${DISTRIB_TIMESTAMP}/${DISTRIB_TIMESTAMP//\//\\\/}/" \
		    -e "s/\${DEVICE_PRODUCT}/${DEVICE_PRODUCT//\//\\\/}/" \
		    -e "s/\${DEVICE_REVISION}/${DEVICE_REVISION//\//\\\/}/" \
		    -e "s/\${DEVICE_MANUFACTURER}/${DEVICE_MANUFACTURER//\//\\\/}/" \
		    -e "s/\${DEVICE_MANUFACTURER_URL}/${DEVICE_MANUFACTURER_URL//\//\\\/}/" \
		    /etc/banner
	else
		cat /etc/banner
	fi
fi

[ -n "$FAILSAFE" ] && cat /etc/banner.failsafe

fgrep -sq '/ overlay ro,' /proc/mounts && {
	echo 'Your overlay partition seems full and overlayfs is mounted read-only.'
	echo 'Please try to remove files from /overlay/upper/... and reboot!'
}

export PATH="/usr/sbin:/sbin:/usr/bin:/bin"
export HOME=$(grep -e "^${USER:-root}:" /etc/passwd | cut -d ":" -f 6)
export HOME=${HOME:-/root}
export PS1='\[\e[1;32m\][\u@\h \w]\$\[\e[0m\] '
export ENV=/etc/shinit

case "$TERM" in
	xterm*|rxvt*)
		export PS1='\[\e]0;\u@\h: \w\a\]'$PS1
		;;
esac

[ -n "$FAILSAFE" ] || {
	for FILE in /etc/profile.d/*.sh; do
		[ -e "$FILE" ] && . "$FILE"
	done
	unset FILE
}

if ( grep -qs '^root::' /etc/shadow && \
     [ -z "$FAILSAFE" ] )
then
cat << EOF

=== WARNING! ========================================================

    There is no root password defined on this device!
    Use the "passwd" command to set up a new password
    in order to prevent unauthorized SSH logins.

=====================================================================
EOF
fi
